package edu.unf.cen6940.web;

import edu.unf.cen6940.dao.GeneratedproductDAO;
import edu.unf.cen6940.dao.ThesisDAO;

import edu.unf.cen6940.domain.Generatedproduct;
import edu.unf.cen6940.domain.Thesis;

import edu.unf.cen6940.service.GeneratedproductService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;

/**
 * Spring MVC controller that handles CRUD requests for Generatedproduct entities
 * 
 */

@Controller("GeneratedproductController")
public class GeneratedproductController {

	/**
	 * DAO injected by Spring that manages Generatedproduct entities
	 * 
	 */
	@Autowired
	private GeneratedproductDAO generatedproductDAO;

	/**
	 * DAO injected by Spring that manages Thesis entities
	 * 
	 */
	@Autowired
	private ThesisDAO thesisDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Generatedproduct entities
	 * 
	 */
	@Autowired
	private GeneratedproductService generatedproductService;

	/**
	 * Select the Generatedproduct entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteGeneratedproduct")
	public ModelAndView confirmDeleteGeneratedproduct(@RequestParam Integer generatedProductIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("generatedproduct", generatedproductDAO.findGeneratedproductByPrimaryKey(generatedProductIdKey));
		mav.setViewName("generatedproduct/deleteGeneratedproduct.jsp");

		return mav;
	}

	/**
	 * Select an existing Generatedproduct entity
	 * 
	 */
	@RequestMapping("/selectGeneratedproduct")
	public ModelAndView selectGeneratedproduct(@RequestParam Integer generatedProductIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("generatedproduct", generatedproductDAO.findGeneratedproductByPrimaryKey(generatedProductIdKey));
		mav.setViewName("generatedproduct/viewGeneratedproduct.jsp");

		return mav;
	}

	/**
	 * Save an existing Generatedproduct entity
	 * 
	 */
	@RequestMapping("/saveGeneratedproduct")
	public String saveGeneratedproduct(@ModelAttribute Generatedproduct generatedproduct) {
		generatedproductService.saveGeneratedproduct(generatedproduct);
		return "forward:/indexGeneratedproduct";
	}

	/**
	 * Delete an existing Generatedproduct entity
	 * 
	 */
	@RequestMapping("/deleteGeneratedproduct")
	public String deleteGeneratedproduct(@RequestParam Integer generatedProductIdKey) {
		Generatedproduct generatedproduct = generatedproductDAO.findGeneratedproductByPrimaryKey(generatedProductIdKey);
		generatedproductService.deleteGeneratedproduct(generatedproduct);
		return "forward:/indexGeneratedproduct";
	}

	/**
	 * Select the child Thesis entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteGeneratedproductThesises")
	public ModelAndView confirmDeleteGeneratedproductThesises(@RequestParam Integer generatedproduct_generatedProductId, @RequestParam Integer related_thesises_thesisId) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("thesis", thesisDAO.findThesisByPrimaryKey(related_thesises_thesisId));
		mav.addObject("generatedproduct_generatedProductId", generatedproduct_generatedProductId);
		mav.setViewName("generatedproduct/thesises/deleteThesises.jsp");

		return mav;
	}

	/**
	 * Edit an existing Generatedproduct entity
	 * 
	 */
	@RequestMapping("/editGeneratedproduct")
	public ModelAndView editGeneratedproduct(@RequestParam Integer generatedProductIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("generatedproduct", generatedproductDAO.findGeneratedproductByPrimaryKey(generatedProductIdKey));
		mav.setViewName("generatedproduct/editGeneratedproduct.jsp");

		return mav;
	}

	/**
	 * Create a new Thesis entity
	 * 
	 */
	@RequestMapping("/newGeneratedproductThesises")
	public ModelAndView newGeneratedproductThesises(@RequestParam Integer generatedproduct_generatedProductId) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("generatedproduct_generatedProductId", generatedproduct_generatedProductId);
		mav.addObject("thesis", new Thesis());
		mav.addObject("newFlag", true);
		mav.setViewName("generatedproduct/thesises/editThesises.jsp");

		return mav;
	}

	/**
	 * Register custom, context-specific property editors
	 * 
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	 * Edit an existing Thesis entity
	 * 
	 */
	@RequestMapping("/editGeneratedproductThesises")
	public ModelAndView editGeneratedproductThesises(@RequestParam Integer generatedproduct_generatedProductId, @RequestParam Integer thesises_thesisId) {
		Thesis thesis = thesisDAO.findThesisByPrimaryKey(thesises_thesisId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("generatedproduct_generatedProductId", generatedproduct_generatedProductId);
		mav.addObject("thesis", thesis);
		mav.setViewName("generatedproduct/thesises/editThesises.jsp");

		return mav;
	}

	/**
	 * Show all Generatedproduct entities
	 * 
	 */
	@RequestMapping("/indexGeneratedproduct")
	public ModelAndView listGeneratedproducts() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("generatedproducts", generatedproductService.loadGeneratedproducts());

		mav.setViewName("generatedproduct/listGeneratedproducts.jsp");

		return mav;
	}

	/**
	 * Create a new Generatedproduct entity
	 * 
	 */
	@RequestMapping("/newGeneratedproduct")
	public ModelAndView newGeneratedproduct() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("generatedproduct", new Generatedproduct());
		mav.addObject("newFlag", true);
		mav.setViewName("generatedproduct/editGeneratedproduct.jsp");

		return mav;
	}

	/**
	 */
	@RequestMapping("/generatedproductController/binary.action")
	public ModelAndView streamBinary(@ModelAttribute HttpServletRequest request, @ModelAttribute HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("streamedBinaryContentView");
		return mav;

	}

	/**
	 * View an existing Thesis entity
	 * 
	 */
	@RequestMapping("/selectGeneratedproductThesises")
	public ModelAndView selectGeneratedproductThesises(@RequestParam Integer generatedproduct_generatedProductId, @RequestParam Integer thesises_thesisId) {
		Thesis thesis = thesisDAO.findThesisByPrimaryKey(thesises_thesisId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("generatedproduct_generatedProductId", generatedproduct_generatedProductId);
		mav.addObject("thesis", thesis);
		mav.setViewName("generatedproduct/thesises/viewThesises.jsp");

		return mav;
	}

	/**
	 * Entry point to show all Generatedproduct entities
	 * 
	 */
	public String indexGeneratedproduct() {
		return "redirect:/indexGeneratedproduct";
	}

	/**
	 * Delete an existing Thesis entity
	 * 
	 */
	@RequestMapping("/deleteGeneratedproductThesises")
	public ModelAndView deleteGeneratedproductThesises(@RequestParam Integer generatedproduct_generatedProductId, @RequestParam Integer related_thesises_thesisId) {
		ModelAndView mav = new ModelAndView();

		Generatedproduct generatedproduct = generatedproductService.deleteGeneratedproductThesises(generatedproduct_generatedProductId, related_thesises_thesisId);

		mav.addObject("generatedproduct_generatedProductId", generatedproduct_generatedProductId);
		mav.addObject("generatedproduct", generatedproduct);
		mav.setViewName("generatedproduct/viewGeneratedproduct.jsp");

		return mav;
	}

	/**
	 * Show all Thesis entities by Generatedproduct
	 * 
	 */
	@RequestMapping("/listGeneratedproductThesises")
	public ModelAndView listGeneratedproductThesises(@RequestParam Integer generatedProductIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("generatedproduct", generatedproductDAO.findGeneratedproductByPrimaryKey(generatedProductIdKey));
		mav.setViewName("generatedproduct/thesises/listThesises.jsp");

		return mav;
	}

	/**
	 * Save an existing Thesis entity
	 * 
	 */
	@RequestMapping("/saveGeneratedproductThesises")
	public ModelAndView saveGeneratedproductThesises(@RequestParam Integer generatedproduct_generatedProductId, @ModelAttribute Thesis thesises) {
		Generatedproduct parent_generatedproduct = generatedproductService.saveGeneratedproductThesises(generatedproduct_generatedProductId, thesises);

		ModelAndView mav = new ModelAndView();
		mav.addObject("generatedproduct_generatedProductId", generatedproduct_generatedProductId);
		mav.addObject("generatedproduct", parent_generatedproduct);
		mav.setViewName("generatedproduct/viewGeneratedproduct.jsp");

		return mav;
	}
}